<template>
	<view class="main">
		<view class="input_top">
			
			<form class="search-block" action="javascript:void 0">			
			<input   v-model="key"   @confirm="getlist"  type="search" placeholder="请输入搜索品牌" />
			 </form>
			
			
		</view>
		<uni-indexed-list :options="list" :showSelect="true" @click="bindClick" ></uni-indexed-list>
	</view>
</template>

<script>
	import uniIndexedList from "@/components/uni-indexed-list/uni-indexed-list.vue"
	export default { 
	    components: {uniIndexedList},
		data(){
			return{
				key:'',
				list:[]
				
			}
		},
		async onLoad(options){
			this.getlist()
			
		
		
		},
		methods:{
			//汉字转化拼音取首字母
			getpy(name){
				return this.$api.pinyin.chineseToPinYin(name).slice(0,1)
			},
			//去重
			unique(arr) { // 根据唯一标识no来对数组进行过滤
			　　const res = new Map();  //定义常量 res,值为一个Map对象实例
			　　//返回arr数组过滤后的结果，结果为一个数组   过滤条件是，如果res中没有某个键，就设置这个键的值为1
			　　return arr.filter((arr) => !res.has(arr.no) && res.set(arr.no, 1)) 
			    },
			
			
			input(e) {
				this.key = e.detail.value
			},
			getlist(){
				
				let that = this;
				this.$Request.post4(
					this.$api.httpApi.brand.brand, {"keyword":that.key}
				).then(res => {
					console.log(res.data)
					if (res.code == 1) {
						that.list=[]
							res.data.forEach(item=>{
							var data = {}
								// that.getpy(item.name)
								that.$set(data,"letter",that.getpy(item.name))
								that.$set(data,"data",[])
								data.data.push(item)
								// data.data.push(item.adImage)
								that.list.push(data)
								
							})
						console.log(that.list)
				
					}
					
				})
				
			},
			searchinput(){
				console.log(0)
			}
		},
		
		
	}
	
</script>

<style lang='scss'>
	.input_top{
		position: relative;
		background: #000;
		padding: 20upx 0;
		
	}
	.input_top input{
		width: 90%;
		margin:0 auto;
		height:77upx;
		background:rgba(255,255,255,1);
		padding: 0 20upx;
		font-size: 28upx;
	}
</style>